version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE III OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

/* PRELIMINARIES */

use				"$project_data\ITRM_Dislo_Unique_Top1000.dta", clear
keep				regno rank ttype year logdelT
#d					;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d					cr

/* DEFINE TREATMENT VARIABLE */

qui				tab year, g(ydum)
g					after=year>=2012

/* COLUMN 1-2 (RANK 80-120) */

local				j=1
cap				drop treat treat_*
g					treat=(rank>80 & rank<=120)
g					treat_after=treat*after
g					treat_2010=treat*ydum5
g					treat_2011=treat*ydum5
g					treat_placebo=treat_2010==1 | treat_2011==1
qui				reg logdelT i.year treat treat_after, cluster(regno)
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1
local				i=1
qui				reg logdelT i.year treat treat_after treat_placebo, cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_placebo]
matrix 			table[`i'+3,`j']=_se[treat_placebo]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* COLUMN 3-4 (RANK 70-130) */

cap				drop treat treat_*
g					treat=(rank>70 & rank<=130)
g					treat_after=treat*after
g					treat_2010=treat*ydum5
g					treat_2011=treat*ydum5
g					treat_placebo=treat_2010==1 | treat_2011==1
qui				reg logdelT i.year treat treat_after, cluster(regno)
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1
local				i=1
qui				reg logdelT i.year treat treat_after treat_placebo, cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_placebo]
matrix 			table[`i'+3,`j']=_se[treat_placebo]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* COLUMN 5-6 (RANK 60-140) */

cap				drop treat treat_*
g					treat=(rank>60 & rank<=140)
g					treat_after=treat*after
g					treat_2010=treat*ydum5
g					treat_2011=treat*ydum5
g					treat_placebo=treat_2010==1 | treat_2011==1
qui				reg logdelT i.year treat treat_after, cluster(regno)
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1
local				i=1
qui				reg logdelT i.year treat treat_after treat_placebo, cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_placebo]
matrix 			table[`i'+3,`j']=_se[treat_placebo]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* COLUMN 7-8 (RANK 50-150) */

cap				drop treat treat_*
g					treat=(rank>50 & rank<=150)
g					treat_after=treat*after
g					treat_2010=treat*ydum5
g					treat_2011=treat*ydum5
g					treat_placebo=treat_2010==1 | treat_2011==1
qui				reg logdelT i.year treat treat_after, cluster(regno)
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1
local				i=1
qui				reg logdelT i.year treat treat_after treat_placebo, cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_placebo]
matrix 			table[`i'+3,`j']=_se[treat_placebo]
matrix			table[`i'+4,`j']=e(N)

/* PLACEBO SPECIFICATION */

drop				if year>=2011
drop				after
g					after=year>=2009

/* COLUMN 1-2 (RANK 80-120) */

local				j=1
cap				drop treat treat_*
g					treat=(rank>80 & rank<=120)
g					treat_after=treat*after
qui				reg logdelT i.year treat treat_after, cluster(regno)
local				i=6
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)
local				j=`j'+2

/* COLUMN 3-4 (RANK 70-130) */

cap				drop treat treat_*
g					treat=(rank>70 & rank<=130)
g					treat_after=treat*after
qui				reg logdelT i.year treat treat_after, cluster(regno)
local				i=6
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)
local				j=`j'+2

/* COLUMN 5-6 (RANK 60-140) */

cap				drop treat treat_*
g					treat=(rank>60 & rank<=140)
g					treat_after=treat*after
qui				reg logdelT i.year treat treat_after, cluster(regno)
local				i=6
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)
local				j=`j'+2

/* COLUMN 7-8 (RANK 50-150) */

cap				drop treat treat_*
g					treat=(rank>50 & rank<=150)
g					treat_after=treat*after
qui				reg logdelT i.year treat treat_after, cluster(regno)
local				i=6
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)

/* FORMATTING THE TABLE */ 

svmat 			table
keep				tab*
drop				table9-table12
keep				if _n<=8
g					c11=""
replace			c11="treat $\times$ after" in 1
replace			c11="treat $\times$ 1.(year $\in$ \{2009,2010\})" in 3
replace			c11="Observations" in 5
replace			c11="treat $\times$ after" in 6
replace			c11="Observations" in 8

forvalues 		c=1/8 {
g					c`c'=string(table`c',"%9.3f")
}
foreach			r in 2 4 7 {
forvalues		c=1/8 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/8 {
replace			c`c'=string(table`c',"%15.0fc") in 5
replace			c`c'=string(table`c',"%15.0fc") in 8
}
forvalues		c=2(2)8 {
replace			c`c'="" in 6
replace			c`c'="" in 7
replace			c`c'="" in 8
}
forvalues		c=1(2)7 {
replace			c`c'="" in 3
replace			c`c'="" in 4
}
forvalues		s=1/15 {
g					s`s'="&"
}
g					l="\\"
foreach			r in 2 4 5 7 8 {
replace			l="\\\\" in `r'
}
order				c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 s12 l
browse			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 s12 l

